/**
 * 
 */
package spitfire.ksim.view;

import javax.swing.JInternalFrame;
import javax.swing.event.InternalFrameAdapter;
import javax.swing.event.InternalFrameEvent;

import spitfire.ksim.node.KNode;
import spitfire.ksim.simulator.KOnDestroyListener;

/**
 * @author Adam
 *
 */
public class KNodeViewFrame extends JInternalFrame {
	private static final long serialVersionUID = 5037176881021139249L;
	private KNode node;
	private KOnDestroyListener l;
	public KNodeViewFrame(KNode n,
			String title,
            boolean resizable,
            boolean closable,
            boolean maximizable,
            boolean iconifiable) {
		super(title, resizable, closable, maximizable, iconifiable);
		this.node = n;
		
		l = new KOnDestroyListener() {
			@Override
			public void onDestroy() {
				KNodeViewFrame.this.dispose();
			}
		};
		node.addOnDestroyListener(l);
		
		addInternalFrameListener(new InternalFrameAdapter() {
			@Override
			public void internalFrameClosed(InternalFrameEvent e) {
				node.removeOnDestroyListener(l);
			}
		});
	}
}
